From: Keir Fraser Date: Tue, 1 Jul 2008 09:58:43 +0000 (+0100) Subject: xend: improve the rotation of qemu-dm logfiles. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~14192^2~7 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22%22/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22%22?a=commitdiff_plain;h=da67ff89f75e515d873ab42169aed36603b38183;p=xen.git xend: improve the rotation of qemu-dm logfiles. Signed-off-by: Yosuke Iwamatsu --- diff --git a/tools/examples/xend-config.sxp b/tools/examples/xend-config.sxp index b6c5ceca26..5c1b6ec446 100644 --- a/tools/examples/xend-config.sxp +++ b/tools/examples/xend-config.sxp @@ -242,3 +242,6 @@ # Script to run when the label of a resource has changed. #(resource-label-change-script '') + +# Rotation count of qemu-dm log file. +#(qemu-dm-logrotate-count 10) diff --git a/tools/python/xen/xend/XendOptions.py b/tools/python/xen/xend/XendOptions.py index aec8134be7..707892f90e 100644 --- a/tools/python/xen/xend/XendOptions.py +++ b/tools/python/xen/xend/XendOptions.py @@ -132,6 +132,9 @@ class XendOptions: """Default script to configure a backend network interface""" vif_script = osdep.vif_script + """Default rotation count of qemu-dm log file.""" + qemu_dm_logrotate_count = 10 + def __init__(self): self.configure() @@ -351,6 +354,10 @@ class XendOptions: def get_vnc_x509_verify(self): return self.get_config_string('vnc-x509-verify', self.xend_vnc_x509_verify) + def get_qemu_dm_logrotate_count(self): + return self.get_config_int("qemu-dm-logrotate-count", + self.qemu_dm_logrotate_count) + class XendOptionsFile(XendOptions): diff --git a/tools/python/xen/xend/image.py b/tools/python/xen/xend/image.py index 5ee9a8d95f..4cf792fe88 100644 --- a/tools/python/xen/xend/image.py +++ b/tools/python/xen/xend/image.py @@ -378,10 +378,18 @@ class ImageHandler: # keep track of pid and spawned options to kill it later self.logfile = "/var/log/xen/qemu-dm-%s.log" % str(self.vm.info['name_label']) - if os.path.exists(self.logfile): - if os.path.exists(self.logfile + ".1"): - os.unlink(self.logfile + ".1") - os.rename(self.logfile, self.logfile + ".1") + + # rotate log + logrotate_count = XendOptions.instance().get_qemu_dm_logrotate_count() + if logrotate_count > 0: + if os.path.exists("%s.%d" % (self.logfile, logrotate_count)): + os.unlink("%s.%d" % (self.logfile, logrotate_count)) + for n in range(logrotate_count - 1, 0, -1): + if os.path.exists("%s.%d" % (self.logfile, n)): + os.rename("%s.%d" % (self.logfile, n), + "%s.%d" % (self.logfile, (n + 1))) + if os.path.exists(self.logfile): + os.rename(self.logfile, self.logfile + ".1") null = os.open("/dev/null", os.O_RDONLY) logfd = os.open(self.logfile, os.O_WRONLY|os.O_CREAT|os.O_TRUNC|os.O_APPEND)